package com.example.administrator.x3picturetransliteration.Home.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.x3picturetransliteration.Bean.ReplyBean;
import com.example.administrator.x3picturetransliteration.R;
import com.example.administrator.x3picturetransliteration.Util.Img.PicassoEqualProportionTransformation2;
import com.example.administrator.x3picturetransliteration.Util.Img.TailorImageView;
import com.squareup.picasso.Picasso;

import java.util.Arrays;
import java.util.List;

/**
 * 反馈记录
 * Created by Administrator on 2019/8/29.
 */

public class FeedbackRecordDialog extends Dialog{

    private View imgView1,imgView2;
    private ImageView[] imgs = new ImageView[6];

    private ReplyBean data;

    public FeedbackRecordDialog(@NonNull Context context,ReplyBean data) {
        super(context, R.style.HomeDialog);

        this.data = data;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_dialog_feedback_record);

        imgView1 = findViewById(R.id.imgView1);
        imgView2 = findViewById(R.id.imgView2);

        imgs[0] = findViewById(R.id.img1);
        imgs[1] = findViewById(R.id.img2);
        imgs[2] = findViewById(R.id.img3);
        imgs[3] = findViewById(R.id.img4);
        imgs[4] = findViewById(R.id.img5);
        imgs[5] = findViewById(R.id.img6);

        ((TextView)findViewById(R.id.TimeText)).setText(data.getReplyTime());
        ((TextView)findViewById(R.id.contentText)).setText(data.getReplyContent());

        List<String> imgas = Arrays.asList(data.getReplyImgs().split(","));

        if (imgas.size()>0)imgView1.setVisibility(View.VISIBLE);
        if (imgas.size()>3)imgView2.setVisibility(View.VISIBLE);

        for (int i=0;i<imgas.size();i++){

            if (i>=6)return;

            imgs[i].setVisibility(View.VISIBLE);

            Picasso.with(getContext())
                    .load(imgas.get(i))
                    .placeholder(R.drawable.home_advertisement)
                    .error(R.drawable.home_advertisement)
                    .transform(new TailorImageView())
                    .transform(new PicassoEqualProportionTransformation2(imgs[i]))
                    .into(imgs[i]);

        }

        findViewById(R.id.okText).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                FeedbackRecordDialog.this.dismiss();
            }
        });

    }

    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity= Gravity.CENTER;
        layoutParams.width= WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height= WindowManager.LayoutParams.WRAP_CONTENT;

        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);

    }

}
